//
// Created by 23602 on 25-8-28.
//

#ifndef CANVAS_HPP
#define CANVAS_HPP

#include <SFML/Graphics.hpp>

class Canvas {
public:
    const int SCREEN_WIDTH;
    const int SCREEN_HEIGHT;

    Canvas(int width, int height): SCREEN_WIDTH(width), SCREEN_HEIGHT(height)
    {
        screen.setPrimitiveType(sf::PrimitiveType::Points);
    }

    const sf::VertexArray& getScreenPixel()
    {
        return this->screen;
    }

    void putPixel(const sf::Vector2f& pos, const sf::Color& color)
    {
        auto pos2 = this->transformCoord(pos);
        screen.append({pos2, color});
    }

    void putPixel(const std::vector<sf::Vector2f>& pos, const sf::Color& color)
    {
        for (const auto& pixel : pos) {
            putPixel(pixel, color);
        }
    }

    void clear()
    {
        screen.clear();
    }

    void drawLine(const sf::Vector2f& p0, const sf::Vector2f& p1, const sf::Color& color);
    void drawTriangle(const sf::Vector2f& p0, const sf::Vector2f& p1, const sf::Vector2f& p2, const sf::Color& color);
    void drawFilledTriangle(const sf::Vector2f& p0, const sf::Vector2f& p1, const sf::Vector2f& p2, const sf::Color& color);
private:
    sf::VertexArray screen;

    sf::Vector2f transformCoord(const sf::Vector2f& coord) const;
};



#endif //CANVAS_HPP
